package com.yjzx.util.common.util.batch.mergingLimit;

/**
 * @author guozhi
 * @date 2025/1/13
 * @description Slot
 */

import lombok.Data;

import java.util.function.Function;
@Data
public class MergingSlot<T, U extends Comparable<U>, R> implements Comparable<MergingSlot<T, U, R>>,Slot, NotNullParam {
    U start;
    U end;
    Function<T, R> result;

    public MergingSlot(U start, U end, Function<T, R> resultFunc) {
        this.start = start;
        this.end = end;
        this.result = resultFunc;
        check();
        if (start.compareTo(end) >= 0) {
            throw new IllegalArgumentException("start must be less than end");
        }
    }

    @Override
    public int compareTo(MergingSlot<T, U, R> other) {
        int startComparison = this.start.compareTo(other.start);
        if (startComparison != 0) {
            return startComparison;
        }
        return this.end.compareTo(other.end);
    }
}
